package dreampack.dataType;

//import java.lang.*;
import java.sql.*;
import java.util.*;
import dreampack.*;
import dreampack.dataQuery.*;

public class UserType extends UserBase {
	private boolean bMultiRole;
	private HashMap userEx;
	
	public UserType(){
		this.userEx = new HashMap();
	}
	
	public boolean init(DreamDB dreamDb, ResultSet rs) throws Exception{
		boolean bRet = true;
		try{
			if (!super.init(rs))
				bRet = false;
			int role = super.getRole();
			this.bMultiRole = false;
			int nMod = role;
			while (1 < role){
				nMod = role % 2; 
				if (0 == nMod){
					role /= 2;
					continue;
				}else {
					this.bMultiRole = true;
					break;
				}
			}
		}catch(Exception e){
			bRet = false;
		}
		return bRet;
	}
	public boolean isMultiRole(){
		return this.bMultiRole;
	}
	public boolean isAdmin(){
		boolean bRet = false;
		int role = super.getRole();
		if ((role & 1) == 1)
			bRet = true;
		return bRet;
	}
	public boolean isTeacher(){
		boolean bRet = false;
		int role = super.getRole();
		if ((role & 2) == 2)
			bRet = true;
		return bRet;
	}
	public boolean isStudent(){
		boolean bRet = false;
		int role = super.getRole();
		if ((role & 4) == 4)
			bRet = true;
		return bRet;
	}
	public boolean isGenearch(){
		boolean bRet = false;
		int role = super.getRole();
		if ((role & 8) == 8)
			bRet = true;
		return bRet;
	}
	public boolean isGuest(){
		boolean bRet = false;
		if (super.getRole() == 0)
			bRet = true;
		return bRet;
	}
	public int getId(){
		return super.getId();
	}
	public String getName(){
		return super.getName();
	}
	public String getPassword(){
		return super.getPassword();
	}
	public int getRole(){
		return super.getRole();
	}
	public String getRealName(){
		return super.getRealName();
	}
	public String getNickName(){
		return super.getNickName();
	}
	public String getSex(){
		return super.getSex();
	}
	public java.util.Date getBirthday(){
		return super.getBirthday();
	}
	public String getHeadImage(){
		return super.getHeadImage();
	}
	public String getTelephone(){
		return super.getTelephone();
	}
	public String getEmail(){
		return super.getEmail();
	}
	public String getMsn(){
		return super.getMsn();
	}
	public String getQQ(){
		return super.getQQ();
	}
	public String getAddress(){
		return super.getAddress();
	}
	public String getPostalCode(){
		return super.getPostalCode();
	}
	public String getSelfIntroduce(){
		return super.getSelfIntroduce();
	}
	public java.util.Date getLastLogTime(){
		return super.getLastLogTime();
	}
	public Object getUserEx(DreamDB dreamDb, String key) throws Exception{
		Object tempObj = null;
		if (this.userEx.get(key) == null){
			if (key == "Admin"){}
			else if (key == "Teacher"){
				tempObj = TeacherQuery.queryById(dreamDb, super.getId());
			}
			else if (key == "Student"){
				tempObj = StudentQuery.qeuryById(dreamDb, super.getId());
			}
			else if (key == "Genearch"){
				tempObj = GenearchQuery.queryById(dreamDb, super.getId());
			}
			else if (key == "Guest"){
				tempObj = null;
			}
			else {}
			this.userEx.put(key, tempObj);
		}
		return this.userEx.get(key);
	}
	
}
